#include<iostream>
#include<cmath>
#include<queue>
#include<string>
#include<math.h>
#include<stack>
#include<vector>
#include<set>
#include <unordered_map>
using namespace std;
template<class container>
void print(const container& c)
{
    typename container::const_iterator it = c.begin();
    while (it != c.end())
    {
        cout << *it << ' ';
        it++;
    }
    cout << endl;
}
namespace ve
{
    template<class t>
    class stack :public vector<t>
    {
    public:
        void push(t a)
        {
            vector<t>::push_back(a);
        }
        void pop()
        {
            vector<t>::pop_back();
        }
    };
}
class person
{
public:
    person(string name, string address) 
    {
        _name = name;
        _address = address;
        cout << "person(string& name,string& address)" << endl;
    }
    person(const person& p1)
    {
        _name = p1._name;
        _address = p1._address;
        cout << "person(const person& p1)" << endl;
    }
    person& operator=(const person& p1)
    {
        if (this != &p1)
        {
            _name = p1._name;
            _address = p1._address;
        }
        cout << "person& operator=(const person& p1)" << endl;
        return *this;
    }
    ~person()
    {
        cout << "~person()" << endl;
    }
protected:
    string _name;
    string _address;
};
class student:public person
{
public:
    student(int num, string name, string address)
        :_num(num),
        person(name,address)
    {
        cout << "student(int num, string name, string address)" << endl;
    }
    student(const student& s1)//这是拷贝构造，可以不写，编译器自动生成的也是ok的，内置类型进行内置值类型的拷贝，自定义类型进行自定义类型相应的拷贝构造
        //但是涉及深拷贝的需要自己写
        :_num(s1._num),
        person(s1)//这个地方会自动进行引用和指针的切片，只取到student中的person部分。
    {
        cout << "student(const student& s1)" << endl;
    }
    student(int num,person& p1)
        :_num(num),
        person(p1)
    {
        cout << "student(int num,person p1)" << endl;
    }
    student& operator=(const student s1)
    {
        if (this != &s1)
        {
            _num = s1._num;
            person::operator=(s1);
        }
        cout << "student& operator=(const student s1)" << endl;
        return* this;
    }
    ~student()//子类的析构不需要显示的去调用父类的析构函数，编译器会先进行父类的析构再自动进行子类的析构
    {
        cout << " ~student()" << endl;
    }
protected:
    int _num;
};
int main()
{
    ve:stack<int> st1;
    person p1("ve", "abc");
    person p2(p1);
    student s1(1, p1);
    student s2(2, p1);
    s2 = s1; //调用 student 的拷贝构造函数生成临时对象（s1的副本）
        //在赋值操作结束后，立即析构这个临时对象
    return 0;
}